package com.zkh.myutils.io.excel.opcpack;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import com.zkh.myutils.utils.DateUtils;

/**
 * docProps部分
 * @author zkh
 */
class DocProps {
	
	/**
	 * core.xml生成
	 * @return
	 */
	public static InputStream getCoreInputStream() {
		//日期
		String date = DateUtils.now("yyyy-MM-dd'T'HH:mm:ss'Z'");
		//拼接内容
		StringBuilder coreText = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
		coreText.append("<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
		coreText.append("<dc:creator>myutils</dc:creator><cp:lastModifiedBy>myutils</cp:lastModifiedBy>");
		coreText.append("<dcterms:created xsi:type=\"dcterms:W3CDTF\">").append(date).append("</dcterms:created>");
		coreText.append("<dcterms:modified xsi:type=\"dcterms:W3CDTF\">").append(date).append("</dcterms:modified>");
		coreText.append("</cp:coreProperties>");
		//返回流
		return new ByteArrayInputStream(coreText.toString().getBytes());
	}
	
	/**
	 * app.xml生成
	 * @param sheetNameList sheet名称集合（有序）
	 * @return
	 */
	public static InputStream getAppInputStream(List<String> sheetNameList) {
		//数量
		int n = sheetNameList.size();
		//拼接内容
		StringBuilder appText = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
		appText.append("<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">");
		appText.append("<Application>myutils</Application><DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop>");
		appText.append("<HeadingPairs><vt:vector size=\"2\" baseType=\"variant\"><vt:variant><vt:lpstr>工作表</vt:lpstr></vt:variant><vt:variant><vt:i4>"+n+"</vt:i4></vt:variant></vt:vector></HeadingPairs>");
		appText.append("<TitlesOfParts><vt:vector size=\"" + n + "\" baseType=\"lpstr\">");
		sheetNameList.forEach(name->appText.append("<vt:lpstr>").append(name).append("</vt:lpstr>"));
		appText.append("</vt:vector></TitlesOfParts>");
		appText.append("<Company></Company><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged>");
		appText.append("</Properties>");
		//返回流
		return new ByteArrayInputStream(appText.toString().getBytes());
	}
}
